#include<bits/stdc++.h>
#define fir first
#define sec second
#define mkp make_pair
using namespace std;
typedef long long LL;
typedef double db;
typedef pair<int,LL> pil;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=1e5+10;
const LL INF=(1LL<<60);
int n,k;
LL sum[MAXN],f[MAXN];
pil q[MAXN];
int main()
{
	n=read();k=read();
	for(int i=1;i<=n;i++)sum[i]=sum[i-1]+read();
	f[0]=0;
	int l=1,r=0;
	q[++r]=mkp(0,0);
	for(int i=1;i<=n;i++)
	{
		f[i]=f[i-1];
		if(q[l].fir<i-k+1)++l;
		while(l<=r&&q[r].sec<f[i-2]-sum[i-1])--r;
		q[++r]=mkp(i,f[i-2]-sum[i-1]);
		f[i]=max(f[i],sum[i]+q[l].sec);
	}
	printf("%lld\n",f[n]);
	return 0;
}
